home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.02 Feb 93 / Jörg's Folder / Code17.patch.4th < prev    next >
Encoding:
Text File  |  1992-10-21  |  6.6 KB  |  262 lines  |  [TEXT/QED1]

  1. ONLY MAC
  2. ALSO DEVELOPMENT
  3. ALSO FORTH DEFINITIONS
  4. ALSO ASSEMBLER
  5.  
  6. VARIABLE rel1                \ holds addr of offset for JSR d(PC)
  7.  
  8. ( The following code is a inline patch to Mach2 2.14 Segment 17 
  9.   that allows the Editor to properly handle activate 
  10.   events.  There were some problems in System 7.
  11.   This code is a modification of the original routine, and cannot be
  12.   larger than the original routine. )
  13.  
  14. CODE edit.activate.event    \ $002D973C - the original address
  15.     LINK    A2,#$-18
  16.     LEA        $-3A8(A5),A0    \ Ref: EVENT-RECORD
  17.     MOVEA.L    2(A0),A0        \ get window pointer
  18.     MOVE.L    A0,$-4(A2)        \ -> windowpointer
  19.     EXG        D4,A7
  20.     MOVE.L    A0,-(A7)
  21.             _SetPort        \ Trap #$A873
  22.     EXG        D4,A7
  23.     LEA        $-3A8(A5),A0    \ Ref: EVENT-RECORD
  24.     MOVE.W    $E(A0),D0        \ event.modifiers
  25.     MOVEQ.L    #$1,D1            \ 1 if window being activated
  26.     AND.W    D1,D0
  27.     TST.W    D0                \ IF
  28.     BEQ.S    @a                \ +$96 $2D980E
  29.  
  30. \ the edit window is being activated
  31.     MOVEQ.L    #$-1,D0            \ $-1
  32.     MOVE.L    D0,-(A6)
  33.     JSR        $1052(A5)        \ @TEPtr
  34.     MOVE.L    (A6)+,A0
  35.     MOVE.L    (A6)+,D0
  36.     MOVE.W    D0,$62(A0)
  37.  
  38.     MOVE.L    $-4(A2),A0
  39.     MOVEQ.L    #$0,D0            \ $0
  40.     EXG        D4,A7
  41.     MOVE.L    $9E(A0),-(A7)
  42.     MOVE.W    D0,-(A7)
  43.             _HiliteControl    \ Trap #$A95D
  44.  
  45.     MOVE.L    $-4(A2),A0
  46.     MOVE.L    $A2(A0),-(A7)
  47.     MOVE.W    #$FF,-(A7)
  48.             _HiliteControl    \ Trap #$A95D
  49.  
  50.     CLR.L    -(A7)            \ clear space for the Task Pointer
  51.     MOVE.L    $-4(A2),-(A7)    \ get the window pointer
  52.             _GetWRefCon        \ Trap #$A917
  53.     MOVE.L    (A7)+,A0        \ task pointer -> A0
  54.     EXG        D4,A7
  55.  
  56.     MOVE.L    $-4(A2),$48(A0)    \ TaskWindowpointer
  57.  
  58.     MOVEQ.L    #$4A,D0            \ $4A
  59.     MOVE.L    D0,-(A6)
  60.     JSR        $1062(A5)        \ InterfaceVector
  61.     BRA        @b                \ +$122 $2D992C
  62.  
  63. \ deactivate event
  64. @a                            \ $002D980E
  65.     MOVE.L    $-4(A2),-(A6)    \ get windowpointer
  66.     \ 002D9812
  67.     JSR        $-3A18(PC)        \ $2D5DFC - do some processing
  68.     [ HERE 2- rel1 ! ]        \ save the routine offset - fill in later
  69.     EXG        D4,A7
  70.             _InitCursor        \ Trap #$A850
  71.     EXG        D4,A7
  72.     MOVEQ.L    #$0,D0            \ $0
  73.     MOVE.L    D0,-(A6)
  74.     JSR        $1052(A5)        \ @TEPtr
  75.     MOVE.L    (A6)+,A0
  76.     MOVE.L    (A6)+,D0
  77.     MOVE.W    D0,$62(A0)
  78.  
  79.     MOVE.L    $-4(A2),A0
  80.     EXG        D4,A7
  81.     MOVE.L    $9E(A0),-(A7)    \ vertical scroll bar
  82.     MOVE.W    #$FF,-(A7)
  83.             _HiliteControl    \ Trap #$A95D
  84.  
  85.     MOVE.L    $-4(A2),A0
  86.     MOVE.L    $A2(A0),-(A7)    \ horiz scroll bar
  87.     MOVE.W    #$FF,-(A7)
  88.             _HiliteControl    \ Trap #$A95D
  89.     EXG        D4,A7
  90.  
  91.     LEA        $48(A4),A0        \ Ref: TaskWindowPointer
  92.     MOVE.L    A0,-(A6)
  93.     JSR        $C62(A5)        \ OPERATOR
  94.     JSR        $ACA(A5)        \ TASK->
  95.     MOVEA.L    (A6)+,A0        \ @
  96.     MOVE.L    (A0),-(A6)
  97.  
  98.     \ now get the window scheduled for an activate event
  99.     \ this is the new and modified part
  100. @get.activate
  101.     EXG.L    D4,A7
  102.     CLR.W    -(A7)            \ reserve function result
  103.     MOVE.W    #$100,-(A7)        \ only activate events in mask
  104.     LEA        $-18(A2),A0        \ temporary Event record
  105.     MOVE.L    A0,-(A7)        \ push on stack
  106.             _EventAvail
  107.     MOVE.W    (A7)+,D0        \ get the result
  108.     EXG.L    D4,A7
  109.     TST.W    D0                \ if there are no activate events
  110.                             \ then it is probably a Desk accessory
  111.     BEQ.S    @enable.edit
  112.  
  113.     \ there is an activate event in the Event queue, see if it is
  114.     \ the Operator window
  115.     MOVE.W    $-18+$E(A2),D0    \ get modifiers
  116.     BTST    #0,D0            \ is it another deactivate
  117.     BEQ.S    @get.activate    \ go back for another event
  118.  
  119.     \ it is an activate event
  120.     MOVE.L    $-16(A2),D1        \ get the window pointer
  121.     MOVE.L    (A6)+,D0        \ get the OPerator windowptr
  122.     CMP.L    D0,D1            \ are they equal
  123.     BNE.S    @non.Operator
  124.  
  125.     \ the window to be activated is the OPERATOR
  126.     MOVEQ.L    #$4B,D0            \ $4B routine selector
  127.     MOVE.L    D0,-(A6)
  128.     JSR        $1062(A5)        \ InterfaceVector
  129.     BRA.S    @b                \ +$7C $2D992C - exit
  130.  
  131. \ it is not the Operator Window
  132. @non.Operator
  133.     MOVE.L    D1,A0            \ put the Windowpointer in A0
  134.     MOVE.W    $6C(A0),D0        \ get the windowKind
  135.     TST.W    D0                \ IF
  136.     BGE.S    @b                \ +$5E $2D992C - branch if an application window
  137.  
  138. \ the window to be activated is a System window
  139. @enable.Edit
  140.     EXG        D4,A7
  141.     SUBQ.L    #4,A7
  142.     MOVE.W    #$854,-(A7)        \ EDIT menu
  143.             _GetMHandle        \ Trap #$A949
  144.     MOVE.L    (A7)+,D0        \ put menuhandle in D0
  145.     EXG        D4,A7
  146.     MOVE.L    D0,$-8(A2)        \ store the menuhandle
  147.     TST.L    D0                \ IF the menu handle is NIL
  148.     BEQ.S    @b                \ +$38 $2D992C don't try to enable it
  149.  
  150. \ we have a valid EditMenu handle
  151.     EXG        D4,A7
  152.     MOVE.L    D0,-(A7)        \ Edit menu handle
  153.     CLR.W    -(A7)            \ enable entire menu
  154.             _EnableItem        \ Trap #$A939
  155.     MOVE.L    $-8(A2),-(A7)    \ menu handle
  156.     MOVE.W    #1,-(A7)        \ enable the Undo menu selection
  157.             _EnableItem        \ Trap #$A939
  158.     EXG        D4,A7
  159.  
  160. @b                            \ $002D992C
  161.     EXG        D4,A7
  162.     MOVE.L    $-4(A2),-(A7)
  163.             _DrawGrowIcon    \ Trap #$A904
  164.     EXG        D4,A7
  165.     UNLK    A2
  166.     RTS
  167. END-CODE
  168.  
  169. HEADER end.of.new
  170.  
  171. ( The following code is a inline patch to Mach2 2.14 Segment 17 
  172.   that allows the Editor to properly handle a text file being
  173.   opened at startup.  There were some problems in System 7.
  174.   This code is a modification of the original routine, and cannot be
  175.   larger than the original routine. )
  176.  
  177. CODE C17Startup
  178.     \ D2(A4) positive
  179.     \ starting addr is 002DC1CA
  180.     \        _Debugger
  181.     MOVE.L    MACH2.flags,D0    \                            1CA
  182.     BTST    #1,D0            \ Apple Events exist        1CE
  183.     BEQ.S    @old.open        \                            1D0
  184.  
  185.     \ we get here when Apple Events exist, so the file information
  186.     \ is a AppParms record in the SFReply buffer
  187.     \
  188.     LEA        $-4DA(A5),A0    \ FSSSpec.VRefNum                1D2
  189.     BRA.S    @new.open        \                                1D6
  190.  
  191. @old.open
  192.     MOVE.L    $AEC,A0            \ AppParmsHandle in A0            1D8
  193.     MOVEA.L    (A0),A0            \ pointer in A0                    1DE
  194. @new.open
  195.     ADDQ.L    #$4,A0            \ 4+ - bypass count and message    1E0
  196.     MOVE.W    (A0),D0            \ get file volume refnum        1E2
  197.     EXT.L    D0                \                                1E4
  198.     MOVE.L    D0,-(A6)        \ file ioVRefNum                1E6
  199.     ADDQ.L    #6,A0            \ offset to filename            1E8
  200.     MOVE.L    A0,-(A6)        \ ( -- ioVRefNum ioNamePtr )    1EA
  201.     MOVEQ.L    #$2F,D0            \ $2F                            1EC
  202.     MOVE.L    D0,-(A6)        \                                1EE
  203.     NOP                        \                                1F0
  204.     NOP                        \                                1F2
  205. END-CODE
  206. HEADER C17Startup.end
  207. \ final address is $2DC1F4
  208.  
  209. : modify.CODE17
  210.     { | code.handle routine.ptr -- }
  211.  
  212.     ['] end.of.new ['] edit.activate.event -
  213.     $002D9940 $002D973C -
  214.     >
  215.     IF
  216.         CR
  217.         ." New code patch is larger than old.  Aborting …"
  218.         ABORT
  219.     THEN
  220.  
  221.     ASCII CODE 17 CALL GetResource -> code.handle
  222.     code.handle 0= NOT
  223.     IF
  224.         code.handle CALL GetResAttrs
  225.         $E7 AND                                \ clear the locked, protected bits
  226.         code.handle SWAP CALL SetResAttrs
  227.         code.handle CALL HLock DROP
  228.         code.handle @ CALL StripAddress
  229.         $002D973C $002D4C9A - + -> routine.ptr
  230.  
  231.         $-3A18                    \ old offset from IP to routine
  232.         $002D9814 $002D973C -    \ old offset from start to IP
  233.         +                        \ offset from start to routine
  234.         rel1 @ ['] edit.activate.event -    \ new offset from start to IP
  235.         -                        \ offset from new IP to routine 
  236.         rel1 @ W!
  237.  
  238.         routine.ptr 
  239.         $002D9940 $002D973C -
  240.         0
  241.         FILL
  242.  
  243.         ['] edit.activate.event
  244.         routine.ptr
  245.         ['] end.of.new ['] edit.activate.event -
  246.         CMOVE
  247.  
  248.         ( now copy the C17Startup code into place )
  249.         ['] C17Startup
  250.         code.handle @ [ $2DC1CA $2D4C9A - ] LITERAL +
  251.         [ ' C17Startup.end ' C17Startup - ] LITERAL
  252.         CMOVE
  253.  
  254.         code.handle CALL HUnlock DROP
  255.         code.handle CALL ChangedResource
  256.         code.handle CALL WriteResource
  257.         BYE
  258.     ELSE
  259.         CR
  260.         ." CODE 17 could not be loaded."
  261.     THEN
  262.     ;